<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>GLTF模型加载</title>
</head>
<script charset="utf-8"
    src="https://map.qq.com/api/gljs?v=1.exp&key=OB4BZ-D4W3U-B7VVO-4PJWW-6TKDJ-WPB77&libraries=geometry,model"></script>
<style type="text/css">
    html,
    body {
        height: 100%;
        margin: 0px;
        padding: 0px;
        overflow: hidden;
    }

    #container {
        position: relative;
        width: 100%;
        height: 100%;
    }
</style>

<body>
    <div id="container"></div>
    <script>
        var center = new TMap.LatLng(22.534266, 113.946442); // 设置中心点坐标
        // 初始化地图
        var map = new TMap.Map('container', {
            center: center,
            zoom: 19,
            pitch: 50,
            rotation: -20,
        });

        // 定义多个模型配置
        var models = [
            {
                id: 'horse1',
                url: './Horse.gltf',
                position: new TMap.LatLng(22.534266, 113.946442, 0),
                scale: [250, 800, 100],
                rotation: [0, 0, 0] // 旋转角度 [x, y, z]
            },
            {
                id: 'horse2',
                url: './Horse.gltf',
                position: new TMap.LatLng(22.535666, 113.94652, 0),
                scale: [350, 350, 200],
                rotation: [0, 0, 0] // 绕Y轴旋转45度
            },
        ];

        // 存储模型实例的数组
        var modelInstances = [];

        // 批量创建模型
        models.forEach(function (modelConfig) {
            console.log(456456465)
            var model = new TMap.model.GLTFModel({
                url: modelConfig.url,
                map: map,
                id: modelConfig.id,
                position: modelConfig.position,
                scale: modelConfig.scale,
                rotation: modelConfig.rotation
            });

            // 模型加载完成回调
            model.on('loaded', function () {
                console.log('模型 ' + modelConfig.id + ' 加载成功');
            });

            // 模型加载失败回调
            model.on('error', function (error) {
                console.error('模型 ' + modelConfig.id + ' 加载失败:', error);
            });

            // 将模型实例添加到数组中
            modelInstances.push(model);
        });
    </script>
</body>

</html>